package com.rykj.energy.common.config;

import net.anumbrella.seaweedfs.core.FileSource;
import net.anumbrella.seaweedfs.core.FileTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import java.io.IOException;

/**
 * @Author 方便面
 * @Date 2020/10/22 19:26
 * @Version 0.999
 */
@Configuration
public class SeaweedFSConfig {
    @Value("${seaweedfs.host:192.168.0.119}")
    private String host;
    @Value("${seaweedfs.port:9333}")
    private int port;

    @Bean
    @Lazy
    public FileTemplate fileTemplate() {
        FileSource fileSource = new FileSource();
        // SeaweedFS master服务ip地址
        fileSource.setHost(host);
        // SeaweedFS master服务端口
        fileSource.setPort(port);
        try {
            // 启动服务
            fileSource.startup();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new FileTemplate(fileSource.getConnection());
    }
}
